# _*_ coding:utf-8 _*_
# @Time :2021/4/16 14:54
# @Author :yanxia

from public.App_Page import  BasePage
from lib.loggers import log
import time
from lib.func import think_time
import random

class Forum(BasePage):
    # 去论坛
    @think_time
    def go_forum(self):
        self.find_text("论坛").click()

    # 去推荐页面
    @think_time
    def go_tuijian(self):
        self.find_text("论坛").click()
        self.find_text("推荐").click()

    # 去最新页面
    @think_time
    def go_zuixin(self):
        self.find_text("论坛").click()
        self.find_text("最新").click()

    # 去关注页面
    @think_time
    def go_guanzhu(self):
        self.find_text("论坛").click()
        self.find_text("关注").click()

    # 去求助问答页面
    @think_time
    def go_wenda(self):
        self.find_text("首页").click()
        time.sleep(3)
        self.find_text("求助问答").click()

    # 全局的页面返回，根据传的参数可用于返回多层页面
    @think_time
    def go_home(self,ele):
        while True:
            if self.d(text=ele).wait(timeout=1):
                break
            self.d.press("back")

    # 等待元素出现
    def wait_findele(self, ele):
        while True:
            if self.d(text=ele).wait(timeout=1):
                break
            self.d.swipe_ext("up")

    # 去我的页面
    @think_time
    def go_mypage(self):
        self.find_text("我的").click()
        while not self.find_text("我的"):
            # self.back()
            if self.find_text("我的"):
                self.back()
            time.sleep(0.5)

    def scrollable_down(self):
        '''向下滑动到顶部'''
        try:
            self.d.swipe_ext("down")
            time.sleep(1)
        except:
            raise
        finally:
            time.sleep(1)

    @think_time
    def fabu_page(self):
        self.find_text("论坛").click()
        self.find_text("推荐").click()
        self.id_click("com.truckhome.bbs:id/iv_community_main_post")

    #发布长贴
    @think_time
    def res_changtie(self):
        self.find_text("论坛").click()
        self.find_text("推荐").click()
        self.id_click("com.truckhome.bbs:id/iv_community_main_post")
        self.id_click("com.truckhome.bbs:id/id_publish_changtie")

    #发布图文
    @think_time
    def res_tuwen(self):
        self.find_text("论坛").click()
        self.find_text("推荐").click()
        self.id_click("com.truckhome.bbs:id/iv_community_main_post")
        self.text_click("图文")

    # 发布不同标签的普通问答
    @think_time
    def res_wenda(self):
        self.find_text("论坛").click()
        self.find_text("推荐").click()
        self.id_click("com.truckhome.bbs:id/iv_community_main_post")
        self.text_click("问答")

    @think_time
    def global_back(self):
        self.id_click("com.truckhome.bbs:id/iv_global_back")

    # 发布小视频
    @think_time
    def res_xiaoshipin(self):
        self.find_text("论坛").click()
        self.find_text("推荐").click()
        self.id_click("com.truckhome.bbs:id/iv_community_main_post")
        self.text_click("小视频")


    @think_time
    def click_tab_title(self):
        self.find_id("com.truckhome.bbs:id/tv_tab_title").click()


    @think_time
    def find_textcontains(self, ele):
        return self.d(textContains=ele)

    def is_exists_textcontain(self, text):
        return self.d(textContains=text).get_text() == text

    @think_time
    def click_textContains(self, text):
        self.find_textcontains(text).click()

    @think_time
    def find_textStartsWith(self, ele):
        return self.d(textStartsWith=ele)

    @think_time
    def click_textStartsWith(self, text):
        self.click_textStartsWith(text).click()


    @think_time
    def inputtext(self, text):
        return self.d(focused=True).set_text(text)

    def is_exists(self, text):
        return self.d(text=text).get_text() == text



    #滑动一屏
    @think_time
    def get_scorll(self):
        self.d(scrollable=True).scroll()

    # 滚动等待元素出现
    def wait_findele(self, ele):
        while True:
            if self.d(text=ele).wait(timeout=1):
                break
            self.d.swipe_ext("up")

    # 滚动等待包含元素出现
    def wait_containsele(self, ele):
        while True:
            if self.d(textContains=ele).wait(timeout=1):
                break
            self.d.swipe_ext("up")

    # 滑动一屏到最左侧
    @think_time
    def get_scorll_right(self):
        self.d(scrollable=True).scroll.horiz.toBeginning()


    # 向上滑动--可用
    @think_time
    def scrollable_up(self):
        try:
            self.d.swipe_ext("up")
            time.sleep(1)
        except:
            raise
        finally:
            time.sleep(1)

    # 向左滑动--可用
    @think_time
    def scrollable_left(self):
        try:
            self.d.swipe_ext("right")
            time.sleep(1)
        except:
            raise
        finally:
            time.sleep(1)

    # 滑动到最顶端
    @think_time
    def scrollable_top(self):
        try:
            self.d(scrollable=True).scroll.toBeginning()
            time.sleep(1)
        except:
            raise
        finally:
            time.sleep(1)
            self.gohome_forum()

    def close_widows(self):
        self.find_id("com.truckhome.bbs:id/iv_close").click()

    # 发布帖子
    @think_time
    def input_title(self, text):
        self.input_text(self.find_id("com.truckhome.bbs:id/edit_title"), text)

    # 发布帖子
    @think_time
    def input_content(self, text):
        self.input_text(self.find_text("分享精彩正能量的内容将有助于管理员加精"), text)

    #发布图文/小视频
    @think_time
    def input_tuwen_content(self, text):
        self.input_text(self.find_text("分享您精彩的生活时刻"), text)

    # 发布小视频评论
    @think_time
    def input_pinglun_xiaoshipin(self, text):
        self.input_text(self.find_text("来说点什么吧..."), text)

    # 发布长贴评论
    @think_time
    def input_pinglun_chengtie(self, text):
        self.input_text(self.find_text("让我说几句…"), text)

    # 发布图文评论
    @think_time
    def input_pinglun_tuwen(self, text):
        self.input_text(self.find_text("让我说几句…"), text)

    # 回复小视频评论
    @think_time
    def reply_pinglun_xiaoshipin(self, text):
        self.input_text(self.find_id("com.truckhome.bbs:id/et_community_video_comment_input"), text)

    # 回复帖子评论
    @think_time
    def reply_pinglun_tiezi(self, text):
        self.input_text(self.find_id("com.truckhome.bbs:id/et_comment_content"), text)

    #发布问答的标题
    @think_time
    def input_wenda_title(self,text):
        self.input_text(self.find_id("com.truckhome.bbs:id/et_release_title"), text)

    # 发布问答的内容
    @think_time
    def input_wenda_content(self, text):
        self.input_text(self.find_text("您可以补充说明问题内容"), text)

    @think_time
    def share_wechat(self):
        self.text_click("质量保障组-newbest")
        self.text_click("分享")
        self.text_click("返回卡车之家app")








